package com.zhaojp.demo.service.impl;

import com.github.pagehelper.PageHelper;
import com.zhaojp.demo.domain.User;
import com.zhaojp.demo.event.UserRegisterEvent;
import com.zhaojp.demo.mapper.UserMapper;
import com.zhaojp.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("UserService")
public class UserServiceImpl implements UserService {

    @Autowired
    ApplicationContext applicationContext;

    @Resource
    private UserMapper userMapper;

    @Override
    public List<User> getUserInfo(int pageNum, int pageSize) {
        //分页插件
        PageHelper.startPage(pageNum, pageSize);
        return userMapper.findUserInfo();
    }

    @Override
    public void register(User user) {
        //todo

        //发布UserRegisterEvent事件
        applicationContext.publishEvent(new UserRegisterEvent(this, user));
    }
}
